package top.heliming.youyou.search.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.heliming.youyou.common.pojo.PageResult;
import top.heliming.youyou.search.pojo.Goods;
import top.heliming.youyou.search.pojo.SearchRequest;
import top.heliming.youyou.search.service.SearchService;

/**
 * description: //商品搜索
 *
 * @author: heliming
 * @date:2019/06/02 下午 1:48
 */
@RestController
@RequestMapping
public class SearchController {

  @Autowired
  private SearchService searchService;

  /**
   * 搜索商品
   *
   * @param request
   * @return
   */
  @PostMapping("page")
  public ResponseEntity<PageResult<Goods>> search(@RequestBody SearchRequest request) {
    PageResult<Goods> result = this.searchService.search(request);
    if (result == null) {
      return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
    result.getItems().forEach(System.out::println);
    return ResponseEntity.ok(result);
  }
}
